﻿#include "SceneContentTest2.h"
#include "3dMath/ss3dMathFunction.h"
//#include "element/camera/ssThirdPersonCamera.h"
#include "element/render/ssTexture2dRender.h"
#include "element/material/ssTextureMaterial.h"
#include "element/render/ssAxesRender.h"
#include "element/light/ssLight.h"
#include "shader/ssShaderManager.h"
#include "console/ssConsole.h"
#include "node/ssNodeFactory.h"
#include "resmgr/ssResManager.h"
#include "element/material/ssLightMaterial.h"


SceneContentTest2::SceneContentTest2(ssSceneManger& scene)
	:BasicSceneContent(scene)
{
	m_pLightNode = 0;
}

SceneContentTest2::~SceneContentTest2(void)
{
}

void SceneContentTest2::InitNode()
{
	StarSeeker::ssNode* pAxesRE = SS_NODE_FACTORY->CreateAxesNode();
	m_scene.RootNode().AddChild(pAxesRE);

	StarSeeker::ssNode* pStoneNode = SS_NODE_FACTORY->CreatePixelLightTextureModelNode("yunshi_01 DM.tga", "yunshi_01 NM.tga", "yunshi001.OBJEX");
	m_scene.RootNode().AddChild(pStoneNode);
	StarSeeker::ssLightMaterial* pLightMaterial = pStoneNode->GetComponent<StarSeeker::ssLightMaterial>(ssComponent::SS_COMPONENT_MATERIAL);
	pLightMaterial->m_ambientCoefficient.Set(0.0f, 0.0f, 0.0f);
	pStoneNode->Transform().SetPosition(0.0f, 50.0f, 50.0f);

	StarSeeker::ssNode* pTeapotNode = SS_NODE_FACTORY->CreateModelNode("teapot.obj");
	m_scene.RootNode().AddChild(pTeapotNode);
	StarSeeker::ssLightMaterial* pLightMaterial2 = new StarSeeker::ssLightMaterial();
	StarSeeker::ssShader* pShader2 = StarSeeker::ssShaderManager::instance()->Find("vlighting");
	pLightMaterial2->SetShader(pShader2);
	pTeapotNode->ReplacComponent(pLightMaterial2);
	pTeapotNode->Transform().SetPosition(0.0f, 0.0f, -100.0f);
	ssQuaternion r; r.SetEuler(Math3D::gc_HALF_PI, 0.0f, 0.0f);
	pTeapotNode->Transform().SetRotation(r);

	StarSeeker::ssNode* pNode = new StarSeeker::ssNode("Board");
	m_scene.RootNode().AddChild(pNode);
	StarSeeker::ssLightMaterial* pMaterial3 = new StarSeeker::ssLightMaterial();
	pMaterial3->m_ambientCoefficient.Set(0.0f, 0.0f, 0.0f);
	SS_RES_MANAGR->LoadPicture("UINV.tga");
	SS_RES_MANAGR->LoadPicture("2400687.tga");
	StarSeeker::ssTexture2D* pTexture = new StarSeeker::ssTexture2D;
	pTexture->Load("UINV.tga");
	pTexture->Load("2400687.tga");
	pMaterial3->SetTexture(pTexture);
	StarSeeker::ssShader* pTextureShader = StarSeeker::ssShaderManager::instance()->Find("plighting");
	pMaterial3->SetShader(pTextureShader);
	StarSeeker::ssTexture2dRender* pRender = new StarSeeker::ssTexture2dRender();
	pRender->SetDataFromMesh(1, "quad");
	pNode->AddComponent(pMaterial3);
	pNode->AddComponent(pRender);
	pNode->Transform().SetScaling(50.0f, 50.0f, 50.0f);

	m_pLightNode = SS_NODE_FACTORY->CreateDiamondNode();
	m_scene.RootNode().AddChild(m_pLightNode);
	m_pLightNode->Transform().SetPosition(0.0f, 0.0f, 100.0f);
	m_pLightNode->Transform().SetScaling(20.0f, 20.0f, 20.0f);
	ssLight* pLight = new ssLight();
	m_pLightNode->AddComponent(pLight);
}

void SceneContentTest2::OnLeftUp(i32 x, i32 y)
{
}

void SceneContentTest2::OnKeyDown(i32 k)
{
	BasicSceneContent::OnKeyDown(k);
	ssfloat step = 5.0f;
	ssVector3 pos = m_pLightNode->Transform().GetPosition();
	switch (k)
	{
		case 88://x
			{
				pos.x += step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
		case 67://c
			{
				pos.y += step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
		case 90://z
			{
				pos.z += step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
		case 65://a
			{
				pos.z -= step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
		case 83://s
			{
				pos.x -= step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
		case 68://d
			{
				pos.y -= step;
				m_pLightNode->Transform().SetPosition(pos);
			}
			break;
	}
}